package cn.gson.springboot.controller;


import cn.gson.springboot.model.pojos.Customerservice;
import cn.gson.springboot.model.service.CustomerserviceService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class CustomerServiceController {
    @Autowired
    CustomerserviceService customerserviceService;

    @RequestMapping("/customerservice-list")
    @ResponseBody
    public Map<String,Object> complainList(Integer page,Integer size, String search,Integer type) {
         Page<Object> obj = PageHelper.startPage(page, size);
        List<Customerservice> customerservices = customerserviceService.selectAll(search,type);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());//返回总页数
        map.put("rows",customerservices);//返回查到的数据
        return map;
    }

    @RequestMapping("/customerservice-deleteOne")
    @ResponseBody
    public void deleteOne() {
        customerserviceService.deleteOne(2);
    }

   /* @RequestMapping("/customerservice-selectOne")
    @ResponseBody
    public Customerservice selectOne() {
        Customerservice customerservice = customerserviceService.selectOne(2);
        return customerservice;
    }*/

    @RequestMapping("/customerservice-alter")
    @ResponseBody
    public void alter() {
        Customerservice customerservice = new Customerservice();
        customerservice.setServiceTheme("衣服有污渍");
        customerserviceService.alter(1,customerservice);

    }

    //@RequestMapping("/customercare-addCustomercare")
    @RequestMapping(value="/customerservice-addCustomerservice",produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public void addCustomerservice(@RequestBody(required = false) Customerservice customerservice) {
        System.out.println(customerservice);
        customerserviceService.addCustomerservice(customerservice);
    }
}